<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
  var img = document.createElement('img');

  img.referrerPolicy = '';
  assert_equals(img.referrerPolicy, '');
  img.setAttribute('referrerPolicy', '');
  assert_equals(img.referrerPolicy, '');

  img.referrerPolicy = 'no-referrer';
  assert_equals(img.referrerPolicy, 'no-referrer');
  img.setAttribute('referrerPolicy', 'no-referrer');
  assert_equals(img.referrerPolicy, 'no-referrer');
  img.referrerPolicy = 'NO-REFERRER';
  assert_equals(img.referrerPolicy, 'no-referrer');

  img.referrerPolicy = 'origin';
  assert_equals(img.referrerPolicy, 'origin');
  img.setAttribute('referrerPolicy', 'origin');
  assert_equals(img.referrerPolicy, 'origin');
  img.referrerPolicy = 'ORIGIN';
  assert_equals(img.referrerPolicy, 'origin');

  img.referrerPolicy = 'no-referrer-when-downgrade';
  assert_equals(img.referrerPolicy, 'no-referrer-when-downgrade');
  img.setAttribute('referrerPolicy', 'no-referrer-when-downgrade');
  assert_equals(img.referrerPolicy, 'no-referrer-when-downgrade');
  img.referrerPolicy = 'NO-REFERRER-WHEN-DOWNGRADE';
  assert_equals(img.referrerPolicy, 'no-referrer-when-downgrade');

  img.referrerPolicy = 'origin-when-cross-origin';
  assert_equals(img.referrerPolicy, 'origin-when-cross-origin');
  img.setAttribute('referrerPolicy', 'origin-when-cross-origin');
  assert_equals(img.referrerPolicy, 'origin-when-cross-origin');
  img.referrerPolicy = 'ORIGIN-when-cross-origin';
  assert_equals(img.referrerPolicy, 'origin-when-cross-origin');
  img.referrerPolicy = 'ORIGIN-when-cros\u017F-origin';
  assert_equals(img.referrerPolicy, '', 'Should be ASCII-caseless.');

  img.referrerPolicy = 'unsafe-url';
  assert_equals(img.referrerPolicy, 'unsafe-url');
  img.setAttribute('referrerPolicy', 'unsafe-url');
  assert_equals(img.referrerPolicy, 'unsafe-url');
  img.referrerPolicy = 'UNSAFE-URL';
  assert_equals(img.referrerPolicy, 'unsafe-url');

  img.referrerPolicy = 'foo';
  assert_equals(img.referrerPolicy, '');
  img.setAttribute('referrerPolicy', '  origin ');
  assert_equals(img.referrerPolicy, '');
}, 'refrrerPolicy IDL attribute should reflect only known values.');
</script>
